<!--
 * @Description: 
 * @Autor: 田力源
 * @Date: 2023-02-17 16:39:50
 * @LastEditors: 田力源
 * @LastEditTime: 2023-02-20 10:23:28
-->
<template>
    <div class="home">
        <header-main></header-main>
        <router-view></router-view>
    </div>
</template>

<script setup lang="ts">
import headerMain from '@/components/headerMain.vue'
import { userlike } from '@/api/article'
import { ElMessage } from 'element-plus'
import { check } from '@/api/user'
import { useUserStore } from '@/store/index'
const user = useUserStore();
// 每次登录检查是否存在登录信息
const checkLogin = () => {
    if (user.isLogin) return;
    check({}).then((res: any) => {
        if (res.code !== 200) return;
        user.setUserInfo(res.data);
        user.changeLogin(true)
        // 获取用户点赞信息
        userlike(user.userInfo.id).then((res: any) => {
            if (res.code !== 200) return ElMessage.error(res.msg || '获取用户喜欢列表失败')
            const { data } = res
            for (let key in data) {
                data[key] ? data[key] = JSON.parse(data[key]) : '';
            }
            user.setUserLike(data)
        })
    })
}
checkLogin();
</script>

<style scoped lang="scss"></style>